package org.linlinjava.litemall.admin.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.linlinjava.litemall.admin.beans.annotation.LogAnno;
import org.linlinjava.litemall.admin.dto.AdminVersionHistoryDTO;
import org.linlinjava.litemall.admin.service.AdminVersionHistoryService;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.net.MalformedURLException;
@Api(tags = "项目更新日志API")
@RestController
@RequestMapping("/admin/version")
@RequiredArgsConstructor
public class AdminVersionHistoryController extends ResponseUtil {

    private final AdminVersionHistoryService adminVersionHistoryService;

    @ApiOperation("项目版本-「更新记录」")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "limit",value = "limit"),
            @ApiImplicitParam(name = "page",value = "page")
    })
    @LogAnno
    @GetMapping("/history")
    public Response versionHistoey(@RequestParam("limit")Integer limit,
                                       @RequestParam("page")Integer page){
        return adminVersionHistoryService.versionHistoey(limit,page);
    }



    @ApiOperation("项目版本-「添加新迭代号」")
    @LogAnno
    @PostMapping("add")
    public Response versionHistoeyDdd(@RequestBody AdminVersionHistoryDTO adminVersionHistoryDTO){
        return adminVersionHistoryService.versionHistoeyDdd(adminVersionHistoryDTO);
    }

    @ApiOperation("项目版本-「删除记录」")
    @ApiImplicitParam(name = "id",value = "id")
    @LogAnno
    @GetMapping("/delete")
    public Response versionHistoeyDelete(@RequestParam("id")Integer id){
        return adminVersionHistoryService.versionHistoeyDelete(id);
    }

    @ApiOperation("项目版本-「版本详情」")
    @ApiImplicitParam(name = "id",value = "id")
    @LogAnno
    @GetMapping("details")
    public Response versionHistoeyDetails(@RequestParam("id")Integer id){
        return adminVersionHistoryService.versionHistoeyDetails(id);
    }

    @ApiOperation("项目版本-「文件上传」")
    @LogAnno
    @PostMapping("/uploadFile")
    public Response uploadFile(@RequestParam("file") MultipartFile multipartFile){
        return adminVersionHistoryService.uploadFile(multipartFile);
    }

    @GetMapping("/download")
    public void downloadFile(@RequestParam("url")String url, @RequestParam("fileName")String fileName, HttpServletResponse response) throws MalformedURLException {
         adminVersionHistoryService.downloadFile(url,fileName,response);
    }

}
